package com.xsjl.gathering.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xsjl.gathering.dao.GatheringDao;
import com.xsjl.gathering.pojo.Gathering;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * gathering服务层
 * 
 * @author Administrator
 *
 */
@Service
public class GatheringService {

	@Autowired
	private GatheringDao gatheringDao;
	


	/**
	 * 查询全部列表
	 * @return
	 */
	public List<Gathering> findAll() {
		return gatheringDao.selectList(null);
	}

	
	/**
	 * 条件查询+分页
	 * @param whereMap
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Gathering> findSearch(Map whereMap, int page, int size) {
		Page<Gathering> pages = new Page<>(page, size);
		QueryWrapper<Gathering> wrapper = new QueryWrapper<>();
		wrapper.allEq(whereMap);
		return gatheringDao.selectPage(pages, wrapper);
	}

	
	/**
	 * 条件查询
	 * @param whereMap
	 * @return
	 */
	public List<Gathering> findSearch(Map whereMap) {
		QueryWrapper<Gathering> wrapper = new QueryWrapper<>();
		wrapper.allEq(whereMap);
		return gatheringDao.selectList(wrapper);
	}

	/**
	 * 根据ID查询实体
	 * @param id
	 * @return
	 */
	@Cacheable(value = "gathering", key = "#id")
	public Gathering findById(String id) {
		return gatheringDao.selectById(id);
	}

	/**
	 * 增加
	 * @param gathering
	 */
	public void add(Gathering gathering) {
		gatheringDao.insert(gathering);
	}

	/**
	 * 修改
	 * @param gathering
	 */
	@CacheEvict(value = "gathering", key = "#gathering.id")
	public void update(Gathering gathering) {
		gatheringDao.updateById(gathering);
	}

	/**
	 * 删除
	 * @param id
	 */
	@CacheEvict(value = "gathering", key = "#id")
	public void deleteById(String id) {
		gatheringDao.deleteById(id);
	}




}
